package onetotwenty;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import org.junit.Test;

public class ProblemTwelve {
	//TODO : 약수의 갯수 구하는 공식 나중에 적용해보기
	public int divisorNumber(long n) {
		long end = (int) Util.sqrt(n);

		int item = (end * end == n) ? 1 : 0;
		for (long i = 1; i < end; i++) {
			if (n % i == 0) {
				item += 2;
			}
		}

		return item;
	}

	public long sum(long n) {
		return (n * (n + 1)) / 2;
	}

	@Test
	public void testDivisorNumber() {
		assertThat(divisorNumber(25), is(3));
		assertThat(divisorNumber(100), is(9));
		assertThat(divisorNumber(28), is(6));
	}

	@Test
	public void testSum() {
		assertThat(sum(10), is(55L));
	}

	@Test
	public void answer() {
		long i = 1;
		long s = 0;
		while (true) {
			s = sum(i);

			if (divisorNumber(s) >= 500) {
				break;
			}

			i++;
		}

		System.out.println(s);
	}
}
